package com.lab.utils;

import android.content.Context;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import com.lab.logtrack.AppLog;


/**
 * Created by ak
 */
public class KeyboardUtil {

    public static boolean showKeybBoard(final Context context, final View view) {
        boolean result = false;
        if (view == null) return result;
        try {
            view.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (view.requestFocus() || view.requestFocusFromTouch()) {
                        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                        imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
                    }
                }
            }, 100);
            return true;
        } catch (Exception e) {
            AppLog.w(e.getMessage());
        }
        return result;
    }

    public static boolean hideKeybBoard(Context context, View view) {
        boolean result = false;
        if (view == null) return result;
        try {
            InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            result = imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        } catch (Exception e) {
            AppLog.w(e.getMessage());
        }
        return result;
    }

}
